class DataFile < ActiveRecord::Base
    
    attr_accessible :path, :mime_type, :file_size, :created_by, :updated_by
    
    # Relationships:
    belongs_to :document
    
    def self.save_files(files, document)
        logger.debug("FILES: #{files}")
        files.map { |file| save(file, document) }
    end
	
    def self.save(upload, document)
        FileUtils.mkdir_p(document.storage_path)
        dest_path = File.join(document.storage_path, upload.original_filename)
        FileUtils.cp(upload.tempfile, dest_path) 
        File.new(dest_path)
    end
end
